local _, ns = ...
----------------------------------------
function ns.newQueue(max_elements)
    local queue = {
        cap = max_elements,
        head = 1,
        count = 0,
    }

    function queue:push(element)
        if self.count == self.cap then
            local removed_element = self[self.head]
            self[self.head] = element
            self.head = self.head + 1
            if self.head > self.cap then
                self.head = 1
            end
            return removed_element
        else
            self.count = self.count + 1
            self[self.count] = element
            return nil
        end
    end

    function queue:is_full()
        return self.count == self.cap
    end

    function queue:clear()
        self.count = 0
        self.head = 1
    end

    function queue:print()
        print(unpack(self))
    end

    return queue
end
----------------------------------------
function ns.iif(cond, true_val, false_val)
    if cond then
        return true_val
    else
        return false_val
    end
end
----------------------------------------
function ns.tcontains(t, val)
    for _, v in pairs(t) do
        if v == val then
            return true
        end
    end
    return false
end
